package com.xuhj.common;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class CommonUtils {
    public static String[] getFieldsName(Class aClass) {
        Field[] fields = aClass.getDeclaredFields();
        List<Field> fieldList = new ArrayList<>(fields.length);
        for(Field field : fields){
            if(!Objects.isNull(field.getAnnotation(FieldIndex.class))){
                fieldList.add(field);
            }
        }
        fieldList.sort(Comparator.comparingInt(e -> e.getAnnotation(FieldIndex.class).index()));
        return fieldList.stream().map(e -> e.getName()).collect(Collectors.toList()).toArray(new String[0]);
    }
}
